/**
 * @summary 文章模块
 * @description ...
 * @author xxx
 */
import * as articleApi from '@/api/article';
export default {
  namespaced: true,
  state: {
    // 文章列表
    articleList: [],
    detailList: {},
    commentsList: [],
    userProfile: {},
  },
  mutations: {
    SET_ARTICLE_LIST(state, newValue) {
      state.articleList = newValue;
    },
    SET_DETAIL_LIST(state, newValue) {
      state.detailList = newValue;
    },
    SET_COMMENTS_LIST(state, newValue) {
      state.commentsList = newValue;
    },
    SET_USER_LIST(state, newValue) {
      state.userProfile = newValue;
    },

  },
  actions: {
    async updateArticleList({ commit }, id) {
      const res = await articleApi.getArticleList(id);
      commit('SET_ARTICLE_LIST', res);
    },
    async updateDetailsList({ commit }, id) {
      const res = await articleApi.getDetailsList(id);
      commit('SET_DETAIL_LIST', res);
    },
    async updateCommentsList({ commit }, id) {
      const res = await articleApi.getCommentsList(id);
      commit('SET_COMMENTS_LIST', res);
    },
    async updateUserProfile({ commit }) {
      const res = await articleApi.userProfile(id);
      commit('SET_COMMENTS_LIST', res);
    },
  }
}
